﻿using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using JuCheap.Service.Model;

namespace JuCheap.Service.Data
{
    /// <summary>
    /// DbContext
    /// </summary>
    public class JuCheapDbContext : DbContext
    {
        /// <summary>
        /// JuCheapContext
        /// </summary>
        public JuCheapDbContext() : base("jucheap")
        {
            
        }

        /// <summary>
        /// 带参数构造函数
        /// </summary>
        /// <param name="connectionString">数据库连接字符串名称</param>
        public JuCheapDbContext(string connectionString) : base(connectionString)
        {
        }

        /// <summary>
        /// OnModelCreating
        /// </summary>
        /// <param name="modelBuilder"></param>
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //移除一对多的级联删除关系
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
            //移除表名复数形式
            modelBuilder.Conventions.Remove<PluralizingEntitySetNameConvention>();

            //配置实体和数据表的关系
            modelBuilder.Configurations.Add(new UserConfig());
        }

        /// <summary>
        /// User
        /// </summary>
        public DbSet<User> Useres { get; set; } 
    }
}
